<?php

namespace Admin\Model;

use Think\Model;

/**
 * Description of AdminModel
 *
 * @author xtceetg
 */
class UserModel extends Model {

    protected $tableName = "user_info";

    public function getUserList($game_id,$area_num,$refer,$uname,$keywords,$dt1,$dt2,$firstRow, $listRows) {
        $sql = "select u.*,gur.game_id,gur.area_num,gur.rolename,gur.rolelevel,gur.first_time,gur.first_ip,g.gamename,a.areaname from user_info as u left join game_user_relation as gur on u.uid=gur.uid and u.username=gur.username"
                . " left join game_list as g on gur.game_id=g.id left join game_server_list as a on gur.area_num=a.area_num and gur.game_id=a.game_id";
        $where=" where 1=1 ";
        if($game_id!=0){
            $where.=" and gur.game_id='".$game_id."'";
        }
        if($area_num!=0){
            $where.=" and gur.area_num='".$area_num."'";
        }
        if($refer!=0){
            $where.=" and gur.refer='".$refer."'";
        }
        if($uname==1){
            $where.=" and gur.username='".$keywords."'";
        }
        if($uname==2){
            $where.=" and gur.uid='".$keywords."'";
        }
        if($dt1!=''){
            $where.=" and u.reg_time>='".$dt1."'";
        }
        if($dt2!=''){
            $where.=" and u.reg_time<='".$dt2."'";
        }
        $order = " order by u.uid desc";
        $limit = " limit {$firstRow} , {$listRows}";
        if($firstRow!='' || $listRows!=''){
            $query=$sql.$where.$order.$limit;
        }else{
            $query=$sql.$where.$order;
        }
       
        return $this->query($query);    
    }

}
